type CancelFn = (v: (value: void | PromiseLike<void>) => void) => void;

/**
 * 取消Promise的类
 */
class CancelToken {
  promise: Promise<void>;
  constructor(cancelFn: CancelFn) {
    this.promise = new Promise((resolve, reject) => {
      cancelFn(() => {
        setTimeout(console.log, 0, "delay cancelled");
        resolve();
      });
    });
  }
}

export default CancelToken;
